package org.example.controller;


import lombok.RequiredArgsConstructor;
import org.example.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 使用 private final 进行开发的时候，需要引入
 * @RestController
 * @RequiredArgsConstructor 这两个注解
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/customer")
public class CustomerController {

    private final RestTemplate restTemplate;
    private final Config config;

    // 注意启动 ribbon之后，http://localhost:9081/stock/getStock 就不能使用了；
    @RequestMapping("/restTemplateTest")
    public String restTemplateTest(){
        String url="http://localhost:9081/stock/getStock";
        // 发送get请求；
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
        return "库存详情为："+forEntity.getBody();
    }



    @RequestMapping("/nacosRestTemplateTest")
    public String nacosRestTemplateTest(){
        String url="http://stock/stock/getStock";
        // 发送get请求；
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
        return "库存详情为："+forEntity.getBody();
    }

    @RequestMapping("/nacosConfigValue")
    public String nacosConfigValue(){
        return "配置中心的值为："+config.getName();
    }
}
